<?php

/**
 * Ignus Framework
 *
 * @author Sergey Palyanov <sergey.palyanov@gmail.com>
 * @link http://code.google.com/p/ignus-php/
 * @license http://apache.org/licenses/LICENSE-2.0
 * @package Ignus
 * @subpackage Db
 * @since 0.3
 */

namespace Ignus\Db;

/**
 * @package Ignus
 * @subpackage Db
 * @since 0.8.0
 */
interface Query
{
    /**
     * Specify sorting fields
     * @param array $sort
     * @return Query
     */
    public function sort(array $sort);

    /**
     * @param integer $limit Number of documents to fetch
     * @param integer $offset Number of documents to skip
     * @return Query
     */
    public function limit($limit, $offset = 0);

    /**
     * @param array $names Field names to fetch
     * @return Query
     */
    public function fields(array $names);

    /**
     * Transforms cursor data to indexed array
     * @return array Array of documents
     */
    public function getArray();

    /**
     * Fetch the first matching document
     * @return array|null
     */
    public function getOne();

    /**
     * Fetch the first matching document
     * @param string $field Field to fetch
     * @return array|null
     */
    public function getOneField($field);

    /**
     * Returns number of documents matching criteria
     * @return integer
     */
    public function count();
}
